<?php

class CGuideTableDraw
{

public static $instance; 

public static function getInstance()
	{
		//echo "<div id=register-box>";
        if(self::$instance==null)
		  self::$instance=new CGuideTableDraw();
	//   echo "</div>";	  
		return  self::$instance;
	   
    
    }	


    function DrawDivAdBegin(){$tab=func_get_args();if(count(func_get_args())>1){echo "<div id=\"$tab[0]\">";return;} echo "<div class=\"$tab[0]\">";}
    
    function DrawDivAdEnd(){echo "</div>"; }

    function fecha($i){
              
        $con = "select GuiDateIn from pack_has_tour_has_guidetc where idPackTourGui=$i";
        $consulta= CModelo::getInstance()->getData($con);
        //Conteo de pasajeros del tour
        foreach($consulta as $r=>$c){
        $table=$c;
            foreach($table as $r2=>$c2){
            $date = $c2;
            }
        }
  

            $date = explode ("-", $date);
            $actual = date("Y-m-d");
            $actual = explode("-", $actual);      
            //$valoresSegunda = explode ("/", $segunda);   
            $anyoPrimera    = $date[0];    
            $mesPrimera  = $date[1];    
            $diaPrimera   = $date[2];
            $anyoAct    = $actual[0];    
            $mesAct  = $actual[1];    
            $diaAct   = $actual[2];
            
            
            //var_dump($actual);
             $PrimeraJul = gregoriantojd($mesPrimera, $diaPrimera, $anyoPrimera);    
             $ActJul = gregoriantojd($mesAct, $diaAct, $anyoAct);  
  
             if ($ActJul - $PrimeraJul > 0){return 1;} 
             else {return 0;}
            //var_dump($date)   
    }

function DrawTable($title,$table,$growtable,$campos,$id)//obligatorio ID como campo inicial
    {       
    $qu="select ";
    $i = 0;
    foreach($campos as $i=>$valor)
    {
    $qu=$qu."$i,";

    }
    $qu=substr($qu,0,strlen($qu)-1);
 
 
    $qu=$qu." FROM $growtable
            LEFT JOIN  $table ON  $growtable.pack_has_tour_idPackTour =  $table.idPackTour 
            LEFT JOIN  tour ON  $table.TOUR_idTour =  tour.idTour 
            WHERE ((guidetc_idGuide =$id and SerFlag='0')) ORDER BY GuiDateIn DESC";
   
    echo "<div id='content_area_user_title'>";
    echo "<h2> $title</h2>";
    echo "</div>";


    echo	"<form>";						
    echo "<form id='filter-form'>Filtrar operador: <input name='filter' id='filter' value='' maxlength='30' size='30' type='text'></form><br>";
    echo "</form>";
   
    echo "<div class='usersettings_statistics'>"; 
 


    echo "<table class='food_planner'>";
    
    
     echo "<thead>";
    echo "<tr>";    
     foreach($campos as $id=>$valor){
  
    echo "<th>$valor</th>";
    
    }
   
    echo "</thead>";
    echo "<tbody><tr style='display: table-row;'>";

     //echo "<table> <tbody>";
    
    
    // $qu="select*from $table";
    $table=CModelo::getInstance()->getData($qu);
//var_dump($table);
    $cont=0;
    $ruta=CConfig::getInstance()->rutalocal;
    
    
    foreach($table as $campo => $valor)
    { 
        $cont=$cont+1;
        if($cont%2){
        
        echo "<tr class='odd'>";
        $i="";$cont=0;
        foreach($valor as $ida=>$val){ 
            if($cont==0){$i=$val;}
            echo "<td>$val</td>";$cont=$cont+1;
        }
/*---------------------------------------------------------------------------*/
// las referencias debbden de ser modificadas deacuerdo al directorio
//
/*---------------------------------------------------------------------------*/


$numpax = "select count(*) from tour_has_pasajero where tour_idTour=(SELECT TOUR_idTour from pack_has_tour where IdPackTour=$id)";

$numpaxa = CModelo::getInstance()->getData($numpax);

//Conteo de pasajeros del tour
foreach($numpaxa as $r=>$c){
    $table=$c;
    foreach($table as $r2=>$c2){
        $numero = $c2;
    }
    
}

$tour = "SELECT TOUR_idTour from pack_has_tour where IdPackTour=$i"; 
$idTour = CModelo::getInstance()->getData($tour);

foreach($idTour as $r=>$c){
    $table=$c;
    foreach($table as $r2=>$c2){
        $idTour = $c2;
    }
    
}

$procTour = 1; 
//CGuideTableDraw::getInstance()->fecha($i);

echo "<td><a href='$ruta/MDTourGeneral/MDPasajeros/MDPasajeros.php?codigo=$idTour'> $numero </a> </td>";
if($procTour==1){echo "<td> <input type=button onClick=\"parent.location='$ruta/MDGuideData/MDAB/AbEdit.php?codigo=$i&idg=$id&action=1'\" value='Ver AB'>  </td>";}
else{echo "<td> <input type=button onClick=\"parent.location='$ruta/MDGuideData/MDAB/AbEdit.php?codigo=$i&action=1'\" value='Modificar AB'>  </td>";}

echo "<td> <a href='$ruta/MDTourGeneral/CTourEdit.php?codigo=$i'>Editar</a> </td>";
echo "<td><a href='/Christian Monzon1/modificar.php?codigo=$i'>Eliminar</a> </td>";
echo "</tr>";
}
else
{

echo "<tr class='even'> ";
$i2="";$cont2=0;
foreach($valor as $ida => $val)
{ if($cont2==0){$i2=$val;}
echo "<td>$val </td>";$cont2=$cont2+1;
}
echo "<td><a href='$ruta/MDTourGeneral/MDPasajeros/MDPasajeros.php?codigo=$idTour'> $numero </a> </td>";
if($procTour==1){echo "<td> <input type=button onClick=\"parent.location='$ruta/MDGuideData/MDAB/AbEdit.php?codigo=$i2&idg=$id&action=1'\" value='Ver AB'>  </td>";}
else{echo "<td> <input type=button onClick=\"parent.location='$ruta/MDGuideData/MDAB/AbEdit.php?codigo=$i2&action=1'\" value='Modificar AB'>  </td>";}

echo "<td> <a href='$ruta/MDTourGeneral/CTourEdit.php?codigo=$i2'>Editar</a> </td>";
echo "<td><a href='/Christian Monzon1/modificar.php?codigo=$i2'>Eliminar</a> </td>";
echo "</tr>";
}

}
echo "</td></tr></tbody></table><br><br></form>";


echo "</div>";

} 



}
?>